<?php
	$conf = array('id' => intval($_REQUEST['conf_id']));
	
	if ($conf['id'] == 0) {
		warning('New Config Keys can only be created editing the database or database_schema/conf.ini manually.');
		location('/conf/admin/index');
	}
	
	if (local_post()) {
		$errors = array();
		
		if (!empty($errors)) errors($errors);
		else {
			$conf['value'] = db_escape_string($_POST['value']);
			
			$conf = db_save($conf, 'conf');	
			
			if ($_POST['button'] == 'Save and Close') location('/conf/admin/index');
			elseif ($_POST['button'] == 'Save and New') location('/conf/admin/edit');
		}
	}
	
	$conf = db_select($conf['id'], 'conf');
?>

<form action="?conf_id=<?php echo $conf['id']?>" method="post">
	<fieldset>
		<legend>Config Key: <?php echo strtoupper(str_replace(' ', '_', $conf['name']))?></legend>
		
		<label for="value" style="width: 95%;">
			Value
			<textarea type="text" name="value" id="value" style="width: 100%; height: 200px;"><?php echo $conf['value']?></textarea>
		</label>
	</fieldset>
	
	<?php save_buttons(); ?>
</form>